{template 'header'}
<link href="./resource/css/app.css" rel="stylesheet">
<ul class="nav nav-tabs">
    <li class="active"><a href="javascript:;">答题管理</a></li>
    <li class=""><a href="{php echo $this->createWeburl('answer', array('op' => 'addshow'));}">添加题库</a></li>
    <li class=""><a href="{php echo $this->createWeburl('answerRecord');}">答题参与记录</a></li>
</ul>
<form action="./index.php" method="get" class="form-horizontal">
    <input type="hidden" name="c" value="site">
    <input type="hidden" name="a" value="entry">
    <input type="hidden" name="m" value="bh_farm">
    <input type="hidden" name="do" value="answer">
</form>

<div class="panel panel-default">
    <div class="table-responsive panel-body">
        <table class="table table-hover">
            <thead class="navbar-inner">
            <tr>
                <th style="width:80px;">问题</th>
                <th style="width:80px;">答案1</th>
                <th style="width:80px;">答案2</th>
                <th style="width:80px;">正确答案</th>
                <th style="width:80px;">操作</th>
            </tr>
            </thead>
            <tbody>
            {loop $list $item}
            <tr>
                <td>{$item['title']}</td>
                <td>{$item['answer_one']}</td>
                <td>{$item['answer_two']}</td>
                <td>{php echo  $item['correct'] ==1 ? '答案1': '答案2'}</td>
                <td>
                    <a href="{php echo $this->createWeburl('answer', array('op' => 'editshow', 'id' => $item['id']));}" class="btn btn-success btn-sm">编辑</a>
                    <a href="javascript:;" data-id="{$item['id']}" class="delete btn btn-danger btn-sm">删除</a>
                </td>
            </tr>
            {/loop}
            </tbody>
        </table>
    </div>
    {$pager}
</div>
<script type="application/javascript">
    $(function () {
        $('.delete').click(function () {
            if (!confirm('确认要删除该问题')) {
                return false;
            }
            id = $(this).data('id');
            $.post('', {id:id, op:'delete'}, function (data) {
                if (data.status == 1) {
                    location.href = location.href;
                } else {
                    alert('删除失败');
                }

            }, 'json')
        });

        $('.is_down').click(function () {
            if (!confirm('确认要' + $(this).html())) {
                return false;
            }
            id = $(this).data('id');
            $.post('', {id:id, op:'down'}, function (data) {
                if (data.status == 1) {
                    location.href = location.href;
                } else {
                    alert('设置失败');
                }

            }, 'json')
        });

        $('.settop').click(function () {

            id = $(this).data('id');
            $.post('', {id:id, op:'settop'}, function (data) {
                if (data.status == 1) {
                    location.href = location.href;
                } else {
                    alert('删除失败');
                }

            }, 'json')
        });
    });

</script>